package com.xuzao.developer.dao.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuzao.developer.base.model.DevelopPlan;
import com.xuzao.developer.dao.DevelopPlanDao;
import com.xuzao.developer.dto.DevelopPlanDTO;
import com.xuzao.developer.mapper.DevelopPlanMapper;
import com.xuzao.developer.tools.base.BaseServiceSupport;
import com.xuzao.developer.tools.entity.Pager;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;


/**
 * @description 
 * @author xuzao
 * @date 2019-08-09 18:11:13
 **/
@Service("developPlanDao")
public class DevelopPlanDaoImpl extends BaseServiceSupport<DevelopPlan> implements DevelopPlanDao {

	@Resource
	private DevelopPlanMapper developPlanMapper;


	@Override
	public PageInfo<DevelopPlan> list(DevelopPlanDTO dto, Pager pager) {
		Example  criteria = this.assemblyQuerycond(dto);
		if (null != pager) {
			if (null != pager.getPageSize() && null != pager.getPageIndex()) {
				PageHelper.startPage(pager.getPageIndex(), pager.getPageSize());
			}
		}
		PageInfo<DevelopPlan> pageInfo = new PageInfo<>(this.developPlanMapper.selectByExample(criteria));
		return pageInfo;
	}

	//通用查询方法条件组装
	public Example assemblyQuerycond(DevelopPlanDTO dto) {
		Example example = new Example(DevelopPlan.class);
		Example.Criteria c = example.createCriteria();
		Example.Criteria developName = example.createCriteria();
		if (null != dto) {
			if(dto.getProjectId() != null){
				c.andEqualTo("projectId",dto.getProjectId());
			}
			if (dto.getStatus()!=null){
				c.andEqualTo("status",dto.getStatus());
			}
			if (StringUtils.isNotBlank(dto.getDevelopName())){
				developName.orLike("javaer","%"+dto.getDevelopName()+"%").orLike("weber","%"+dto.getDevelopName()+"%")
						.orLike("tester","%"+dto.getDevelopName()+"%");
				example.and(developName);
			}
		}
		return example;
	}
}